MESSAGE( STATUS "Configuring module: Engine...")

# Set Module Name
SET(MODULE_NAME engine)

# Policy
CMAKE_POLICY(SET CMP0020 NEW)

# Set Module Path
SET(MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

# set include files
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH})
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/engine)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/engine/core/render)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/engine/core/render/render)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/engine/core/script/lua)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/spine/)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/FreeImage)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/recast/Recast)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/recast/Detour)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/recast/DetourCrowd)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/recast/DetourTileCache)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/opengles/angle/include)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/physx/physx/include)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/physx/pxshared/include)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/live2d/Cubism31SdkNative-EAP5/Core/include)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/freetype-2.10.0/include)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/RadeonRays/RadeonRays/include)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/google)
INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/google/flatbuffers/include)

IF(${ECHO_PLATFORM_WINDOWS})
	INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/openal-soft/include)
    INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/vulkan/vulkan-headers/include)
    INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/vulkan/vulkan-loader/loader/generated)
    INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/google/protobuf-3.21.6/src)
    INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/libevent/include)
ELSEIF(ECHO_PLATFORM_LINUX)
    INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/openal-soft/include)
    INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/vulkan/linux/x86_64/include)
ELSEIF(ECHO_PLATFORM_ANDROID)
    INCLUDE_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/openal-soft/include)
ENDIF()

# Configure FILE
CONFIGURE_FILE(
	${CMAKE_CURRENT_SOURCE_DIR}/core/base/echo_config.h.in
	${CMAKE_CURRENT_SOURCE_DIR}/core/base/echo_config.h
)

IF(${ECHO_PLATFORM_MAC})
    SET(MAC_MM_FILES *.mm)
ELSE()
    SET(MAC_MM_FILES)
ENDIF()

# Find Qt Packages
TARGET_FIND_QTPACKAGES(${MODULE_NAME})

# Get All Files
FILE(GLOB_RECURSE HEADER_FILES  *.h *.hpp *.inl)
FILE(GLOB_RECURSE SOURCE_FILES  *.cpp *.c *.cc *.cx ${MAC_MM_FILES})

SET(ALL_FILES ${HEADER_FILES} ${SOURCE_FILES} CMakeLists.txt)

# Qt ui files
IF(ECHO_EDITOR_MODE)
    FILE(GLOB_RECURSE UI_FILES  ${CMAKE_CURRENT_SOURCE_DIR}/*.ui)
    GROUP_QT_UI_FILES(QT_GENERATE_FILES UI_FILES ${CMAKE_CURRENT_SOURCE_DIR})

    #GROUP_QT_MOC_FILES(QT_GENERATE_FILES HEADER_FILES)
    INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/engine)
ENDIF(ECHO_EDITOR_MODE)

# Remove render library
IF(${ECHO_PLATFORM_WINDOWS})
    #EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/gles/*.*)
	EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/metal/*.*)
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/d3d11/*.*)
ELSEIF(${ECHO_PLATFORM_MAC})
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/gles/*.*)
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/vulkan/*.*)
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/d3d11/*.*)
ELSEIF(${ECHO_PLATFORM_LINUX})
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/gles/*.*)
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/d3d11/*.*)
ELSEIF(${ECHO_PLATFORM_IOS})
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/vulkan/*.*)
    EXCLUDE_FILES(ALL_FILES GLOB_RECURSE ${MODULE_PATH}/core/render/d3d11/*.*)
ENDIF()

GROUP_FILES_NO_INCLUDE(ALL_FILES ${CMAKE_CURRENT_SOURCE_DIR})

IF(ECHO_UNICODE)
	ADD_DEFINITIONS("-DUNICODE -D_UNICODE")
ENDIF()

IF(ECHO_GAME_SOURCE)
	ADD_DEFINITIONS(-DECHO_GAME_SOURCE)
ENDIF()

ADD_LIBRARY(${MODULE_NAME} STATIC ${ALL_FILES} ${UI_FILES} ${QT_GENERATE_FILES} CMakeLists.txt)

SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES FOLDER "core")

IF(APPLE)
  SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++1z")
ENDIF()

# USE Qt
TARGET_LINK_QTLIBRARIES(${MODULE_NAME})

# Link libraries
TARGET_LINK_LIBRARIES(${MODULE_NAME} pugixml lua icns libpng zlib)
TARGET_LINK_LIBRARIES(${MODULE_NAME} spirv-cross glslang)
TARGET_LINK_LIBRARIES(${MODULE_NAME} nodeeditor)

MESSAGE(STATUS "Configure success!")
